package day02;

import java.util.Objects;

public class Stu implements Comparable<Stu>{
    private Integer id;
    private String name;
    private Integer age;
    private Integer height;
    private Integer weight;

    public Stu(Integer id, String name, Integer age, Integer height, Integer weight) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.height = height;
        this.weight = weight;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Stu stu = (Stu) o;
        return getId().equals(stu.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getId());
    }

    @Override
    public String toString() {
        return "Stu{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", height=" + height +
                ", weight=" + weight +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Integer getHeight() {
        return height;
    }

    public void setHeight(Integer height) {
        this.height = height;
    }

    public Integer getWeight() {
        return weight;
    }

    public void setWeight(Integer weight) {
        this.weight = weight;
    }

    public Stu() {
    }

    /**
     * 1.年龄从大到小
     * 2.如果年龄一样，按身高排序(高到低)
     * 3.如果身高也一样，按体重排序(轻到重)
     */
    @Override
    public int compareTo(Stu o) {
        if(this.age!=o.getAge())//此处也可以用this.age.compareTo(o.getAge())!=0
//引用数据类型进行比较用compareTo()方法，但是Integer类型可以自动拆装箱，所以也可以直接比较
            return o.getAge()-this.getAge();//年龄倒序排列，如果判断用了compareTo，
//这里也可以用o.getAge().compareTo(this.age)
        if (height.compareTo(o.getHeight())!=0)
            return o.getHeight().compareTo(this.height);
        return this.weight.compareTo(o.getWeight());
    }
}
